home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 22 / Cream of the Crop 22.iso / program / asm32.zip / E32.ZIP / DEL_CHAR.ASM < prev    next >
Assembly Source File  |  1995-01-24  |  2KB  |  122 lines

  1. ; DEL_CHAR.ASM for E32 - Copyright (C) 1994 Douglas Herr
  2. ;  all rights reserved
  3.  
  4. ; This deletes the character at the cursor
  5. ; by shifting the remainimg characters forward
  6.  
  7. include    model.inc
  8.  
  9. public    del_char, save_char
  10. extrn    display_bottom:near
  11. extrn    sub_push:near
  12.  
  13. CR    equ    0Dh
  14. LF    equ    0Ah
  15.  
  16. include    dataseg.inc
  17. extrn    filesiz:dword, cursor:dword
  18. extrn    dirty_bits:byte
  19. extrn    cur_posn:word, save_column:byte
  20.  
  21. extrn    undo_length:dword
  22. extrn    undo_buffer:dword
  23. @curseg    ends
  24.  
  25. include    codeseg.inc
  26. del_char    proc    near
  27.     cld
  28.     push    es
  29.     mov    ecx,filesiz
  30.     mov    esi,cursor
  31.     mov    edi,esi
  32.     cmp    esi,ecx        ; are we at the end of the file?
  33.     jae    short no_del    ; if yes, then don't delete
  34.  
  35.     push    ds
  36.     push    fs
  37.     pop    ds
  38.     lodsb
  39.     pop    ds
  40.  
  41.     call    save_char    ; save it for UNDO function
  42.  
  43. ; don't get next character if at end of buffer
  44. ; will cause exception if deleting last character in buffer
  45.     cmp    esi,filesiz
  46.     jae    short shorten_file
  47.  
  48.     push    fs
  49.     pop    es
  50.     mov    ah,es:[esi]    ; look at the next character also
  51. shorten_file:
  52.     push    eax        ; save character we're deleting
  53.     dec    filesiz        ; shorten the file by one
  54.     sub    ecx,esi
  55.  
  56.     push    ds
  57.     push    fs
  58.     pop    ds
  59.     rep    movsb        ; move the file down one notch
  60.     pop    ds
  61.  
  62.     mov    eax,1
  63.     call    sub_push    ; adjust push offset if nessesary
  64.     pop    eax        ; get the character back we deleted
  65.     cmp    al,cr        ; did we delete a CR?
  66.     je    short combine
  67.     or    dirty_bits,11000100b
  68.                 ; current line is dirty
  69. no_del:    clc
  70.     pop    es
  71.     ret
  72.  
  73. combine:cmp    ah,lf        ; is the next char LF?
  74.     jne    short no_del_lf
  75.     call    del_char    ; delete the line feed
  76. no_del_LF:
  77.     call    display_bottom    ; repaint bottom of screen
  78.     mov    dx,cur_posn
  79.     mov    save_column,dl    ; save the cursor column
  80.     clc
  81.     pop    es
  82.     ret
  83.  
  84. del_char    endp
  85.  
  86. ; add a character to the undo buffer
  87.  
  88. save_char:
  89.     mov    ebx,undo_length
  90.     cmp    ebx,128
  91.     jae    short no_save    ; no room
  92.     inc    undo_length    ; one more saved character
  93.     add    ebx,undo_buffer    ; add offset of buffer
  94.     mov    [ebx],al
  95. no_save:
  96.     ret
  97.  
  98. @curseg    ends
  99.  
  100.  
  101. ; UNDO
  102. ;
  103. ;  restores any characters which have recently been deleted
  104.  
  105. public    undo
  106. extrn    insert_string:near
  107.  
  108. include    codeseg.inc
  109. undo    proc    near
  110.     xor    eax,eax
  111.     xchg    eax,undo_length        ; get buffer length
  112.     test    eax,eax
  113.     jz    short exit
  114.     mov    esi,undo_buffer        ; address of undo buffer
  115.     call    insert_string
  116. exit:    clc
  117.     ret
  118. undo    endp
  119.  
  120. @curseg    ends
  121.     end
  122.